//init 
$(document).ready(function() {
	monitor.initOnlineUserTable();
	
	monitor.refreshMonitor();
	
	
});
//namespace
var monitor= {};

monitor.initCreateSwitch = function(){
	$('#createSwitch').lc_switch();
	$(document).delegate('#createSwitch', 'lcs-statuschange', function() {//'.lcs_wrap input'
		monitor.setPublish_key($(this).is(':checked') + "")
	});
}

monitor.initCreateSwitchStatus = function(status){
	if(status){
		$('#createSwitch').lcs_on_notrigger();	
	}else{
		$('#createSwitch').lcs_off_notrigger();	
	}
}

monitor.refreshMonitor = function(){
	var url = "sys/getPublishThread";
	var data = {

		};
	var successCallBack = function(data){
		
		if(data.onlineUsers != undefined){
			monitor.setOnlineUserTableInfo(data.onlineUsers);
		}
		
		
	};
	$.sysAjax( url , data , successCallBack );
}

monitor.initOnlineUserTable = function(){
	
	monitor.onlineUserTable = $('#onlineUserTable').DataTable({
		"scrollX":false,
		"scrollY":false,
		"ordering":false,
		"searching" : false,
		'bStateSave' : false,
		'paging' : false,
		'info' : false,
		language : commonI18n.tableI18n,
		"bServerSide" : false,
	})
//	var tmpTableBody = $("#onlineUserTable").parent();
//	tmpTableBody.perfectScrollbar();
//	tmpTableBody.css("overflow","hidden");
//	tmpTableBody.css("height","200px");
	
}

function adjustTable(){
	$.fn.dataTable.tables( {visible: true, api: true} ).columns.adjust();
}

monitor.setOnlineUserTableInfo = function(users){
	
	monitor.onlineUserTable.clear();
	for(var i = 0; i < users.length; i++){
		var tempInfo = users[i];
		var index = i + 1;
		var host =tempInfo.host;
		var username = tempInfo.username;
		var loginTime = tempInfo.loginTime;
		var isOnline = tempInfo.isOnline;
		
		var tmpRow = [index, host, username, loginTime, isOnline]; 
		monitor.onlineUserTable.row.add(tmpRow);
	}
	monitor.onlineUserTable.draw();
	setTimeout(adjustTable, 100);
}


